import Vue from 'vue'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import 'font-awesome/css/font-awesome.min.css'
import App from '~/views/App.vue'
import router from '~/router'
import Oauth from '~/utils/oauth'
import ajax from '~/utils/ajax'

Vue.use(ElementUI);

router.beforeEach((to, from, next) => {
    if (Oauth.getToken()) {
        if (Oauth.user) {
            next();
        } else {
            Oauth.user = Oauth.loadUserInfo().then(function (result) {
                if (result) {
                    Oauth.user = result;
                    next();
                } else {
                    alert(1)
                }
            });
        }
    } else {
        Oauth.authorize();
    }
});

new Vue({
    el: '#app', router,
    render: h => h(App)
});

